package com.nado.iims2.blog.bo.service;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nado.iims2.blog.dao.service.NamespaceDAO;
import com.nado.iims2.blog.model.service.Namespace;

@Service("NamespaceBO")
public class NamespaceBOImpl implements NamespaceBO {
	private static Log log = LogFactory.getLog(NamespaceBOImpl.class);
	
	@Autowired
	private NamespaceDAO namespaceDAO = null;
	
	@Override
	public List<Namespace> getNamespaceList(int offset, int count) {
		try {
			List<Namespace> result = new ArrayList<Namespace>();
			result = namespaceDAO.selectNamespaceList(offset, count);
			return result;
		} catch (Exception e) {
			log.error(e, e);
			return new ArrayList<Namespace>();
		}
	}

	@Override
	public int getNamespaceListCount() {
		try {
			return namespaceDAO.selectNamespaceListCount();
		} catch (Exception e) {
			log.error(e, e);
			return 0;
		}
	}

	@Override
	public int writeNamespace(Namespace model) {
		int result = 0;
		try {
			if(model.getNo() == 0) {
				result = namespaceDAO.insertNamespace(model);
			} else {
				result = namespaceDAO.updateNamespace(model);
			}
			
		} catch (Exception e) {
			log.error(e, e);
			return -1;
		}
		return result;
	}

}
